home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / generatr / generatr.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  23KB  |  755 lines

  1. /****************************************************************
  2. * GENERATR.C | The Degas Elite Image Toolkit | December 9, 1988 *
  3. * ------------------------------------------------------------- *
  4. * Programmed by Robert M. Birmingham and Richard C. Leinecker.  *
  5. ****************************************************************/
  6.  
  7. #include <obdefs.h>
  8. #include <define.h>
  9. #include <osbind.h>
  10. #include <gemdefs.h>
  11.  
  12. /* define the array positions for each box... */
  13. #define  SCRN1     0
  14. #define  SCRN2     1
  15. #define  SCRN3     2
  16. #define  SCRN4     3
  17. #define  SCRN5     4
  18. #define  SCRN6     5
  19. #define  SCRN7     6
  20. #define  SCRN8     7
  21. #define  CUTIMAGE  8
  22. #define  TO_C      9
  23. #define  TO_ASM   10
  24. #define  TO_GFA   11
  25. #define  TO_DATA  12
  26.  
  27. /* define mixinum and maximum for window redraw code... */
  28. #define maximum(x,y)  (((x) > (y)) ? (x) : (y))
  29. #define minimum(x,y)  (((x) < (y)) ? (x) : (y))
  30.  
  31. /* define the type of window to use... */
  32. #define WI_KIND ( CLOSER | MOVER | NAME | FULLER )
  33.  
  34. /* global application ID number */
  35. extern int gl_apid;
  36.  
  37. /* arrays for GEM bindings... */
  38. int contrl[12];
  39. int intin[128];
  40. int ptsin[128];
  41. int intout[128];
  42. int ptsout[128];
  43. int work_in[11];
  44. int work_out[57];
  45.  
  46. char pathname[128];    /* pathname for file selector    */
  47. char filename[128];    /* filename for saving the image */
  48.  
  49. int handle;            /* workstation handle            */
  50. int menu_id;           /* accessory menu ID number      */
  51. int degas_id;          /* application ID of Degas Elite */
  52. int wi_handle;         /* calculator window handle      */
  53. int gr_hwchar;         /* width of a character cell     */
  54. int gr_hhchar;         /* height of a character cell    */
  55. int mx, my, button;    /* mouse position and button     */
  56. int rx1,ry1,rx2,ry2;   /* rectangle for cut image coord */
  57. int xwork, ywork;      /* position of window work area  */
  58. int wwork, hwork;      /* width and height of work area */
  59. int ax, ay, aw, ah;    /* accessory window coordinates  */
  60. int rez;               /* current system resolution     */
  61. int cutflag;           /* buffer undefined/defined flag */
  62. int cur_screen;        /* currently selected screen box */
  63. int msgbuff[16];       /* evnt_multi() message buffer   */
  64.  
  65. long *scrn_pntrs;      /* pointer to screen pointer list */
  66. long scrn_array[8];    /* holds DE's screen pointers 1-8 */
  67. long temp_scrn;        /* pointer to DE's work screen    */
  68. long undo_scrn;        /* pointer to DE's UNDO buffer    */
  69.  
  70. char image_names[800]; /* array for array names entered  */
  71. int names;             /* number of array names entered  */
  72.  
  73. /* declare an array of structures to hold the box information... */
  74. struct boxdefs
  75.        {
  76.        int x, y;
  77.        int w, h;
  78.        char *string;
  79.        } boxes[] = {
  80.  
  81.        1, 0, 11, 1,  " Screen #1",
  82.        1, 2, 11, 1,  " Screen #2",
  83.        1, 4, 11, 1,  " Screen #3",
  84.        1, 6, 11, 1,  " Screen #4",
  85.        14, 0, 11, 1, " Screen #5",
  86.        14, 2, 11, 1, " Screen #6",
  87.        14, 4, 11, 1, " Screen #7",
  88.        14, 6, 11, 1, " Screen #8",
  89.        1, 8, 24, 1,  "Cut Image",
  90.        1, 10, 24, 1, "Buffer to C",
  91.        1, 12, 24, 1, "Buffer to Assembly",
  92.        1, 14, 24, 1, "Buffer to GFA Basic",
  93.        1, 16, 24, 1, "Buffer to Data File"
  94.        };
  95.  
  96. /* Initialize the key enabled/disabled bitmapped fields... */
  97. int boxflags[] = { 0x0100, 0x1f00 };
  98.  
  99. main()
  100. {
  101.     initialize();    /* initialize the accessory  */
  102.     do_event();      /* handle the message events */
  103. }
  104.  
  105.  
  106. /********************************************************
  107. * do_event():                                           *
  108. * This routine waits for an event, then calls a routine *
  109. * to handle the message event that was returned.        *
  110. ********************************************************/
  111.  
  112. do_event()
  113. {
  114.     int i;         /* miscellaneous variable         */
  115.     int mx, my;    /* mouse position variables       */
  116.     int event;     /* event returned by evnt_multi() */
  117.  
  118.  
  119.     graf_mouse( ARROW, 0x0L );
  120.  
  121.     /* good accessories never die! */
  122.     while( TRUE )
  123.            {
  124.            /* wait for a message or button event */
  125.            event = evnt_multi( MU_BUTTON | MU_MESAG, 1, 1, 1, 
  126.                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127.                                msgbuff, 0, 0, &mx, &my,
  128.                                &i, &i, &i, &i );
  129.  
  130.            /* process the event returned */
  131.            if( event & MU_MESAG ) do_message( msgbuff );
  132.            if( event & MU_BUTTON ) check_box( mx, my );
  133.            }
  134.  
  135. }   /* End of - do_event() */
  136.  
  137.  
  138. /*************************************************************
  139. * do_message():                                              *
  140. * This routine calls the appropriate window event handler    *
  141. * with the information contained in the event message buffer *
  142. *************************************************************/
  143.  
  144. do_message( msgbuff )
  145. int msgbuff[];
  146. {
  147.     switch( msgbuff[0] )
  148.             {
  149.             case AC_OPEN:     acc_open( msgbuff );      break;
  150.             case AC_CLOSE:    acc_close( msgbuff );     break;
  151.             case WM_MOVED:    move_window(msgbuff);     break;
  152.             case WM_CLOSED:   close_window( msgbuff );  break;
  153.             case WM_NEWTOP:   top_window( msgbuff );    break;
  154.             case WM_TOPPED:   top_window( msgbuff );    break;
  155.             case WM_FULLED:   show_authors( msgbuff );  break;
  156.             case WM_REDRAW:   redraw( msgbuff );        break;
  157.             }
  158.  
  159. }   /* End of - do_message() */
  160.  
  161.  
  162. /*************************************
  163. * acc_open():                        *
  164. * This routine opens the accessory   *
  165. * and ask DE for the necessary info. *
  166. *************************************/
  167.  
  168. acc_open( msgbuff )
  169. int msgbuff[];
  170. {
  171.     static char not_found[] = "[1][|Could not find Degas Elite!][ Ok ]";
  172.  
  173.     int i;            /* miscellaneous variable          */
  174.     int event;        /* event returned by evnt_multi()  */
  175.     int demsg[16];    /* buffer for degas elite messages */
  176.  
  177.  
  178.     /* return if the open command is not for us! */
  179.     if( msgbuff[4] != menu_id ) return(0);
  180.  
  181.     /* if the window is already open, just top it and leave! */
  182.     if( wi_handle != -1 )
  183.         {
  184.         wind_set( wi_handle, WF_TOP, 0, 0, 0, 0 );
  185.         return(0);
  186.         }
  187.  
  188.     /* otherwise, try to find Degas Elite and get it's ID # */
  189.     degas_id = appl_find( "DEGELITE" );
  190.  
  191.     /* leave if an invalid ID # is returned */
  192.     if( degas_id < 0 )
  193.         {
  194.         form_alert( 1, not_found );
  195.         return(0);
  196.         }
  197.  
  198.     /* Make sure DE is there! */
  199.     demsg[0] = 0xDE00;
  200.     demsg[1] = gl_apid;
  201.     demsg[2] = 0;
  202.     i = appl_write( degas_id, 16, demsg );
  203.  
  204.     /* wait for a reply from DE, or for a timer to elapse */
  205.     event = evnt_multi( MU_MESAG|MU_TIMER, -1, -1, -1,
  206.                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  207.                         demsg, 2000, 0,
  208.                         &i, &i, &i, &i, &i, &i );
  209.  
  210.     /* if the timer elapsed, then DE didn't respond! */
  211.     if( event & MU_TIMER )
  212.         {
  213.         form_alert( 1, not_found );
  214.         return(0);
  215.         }
  216.  
  217.     /* I think it's ok to ignore if the message isn't of interest */
  218.     if( demsg[0] != 0xDE80 ) return(0);
  219.  
  220.     /* otherwise, ask Degas Elite for the buffer pointers */
  221.     demsg[0] = 0xDE00;
  222.     demsg[1] = gl_apid;
  223.     demsg[2] = 0;
  224.     appl_write( degas_id, 16, demsg );
  225.  
  226.     /* wait for a reply from DE */
  227.     do{ evnt_mesag( demsg ); } while( demsg[0] != 0xDE80 );
  228.  
  229.     /* grab the pointer to the array of screen pointers */
  230.     scrn_pntrs = (long *)(((long)demsg[3] << 16) |
  231.                  (((long)demsg[4]) & 0x0000ffffL));
  232.  
  233.     /* copy the drawing screen pointers to my array */
  234.     scrn_array[ SCRN1 ] = scrn_pntrs[ 1 ];
  235.     scrn_array[ SCRN2 ] = scrn_pntrs[ 2 ];
  236.     scrn_array[ SCRN3 ] = scrn_pntrs[ 7 ];
  237.     scrn_array[ SCRN4 ] = scrn_pntrs[ 8 ];
  238.     scrn_array[ SCRN5 ] = scrn_pntrs[ 9 ];
  239.     scrn_array[ SCRN6 ] = scrn_pntrs[ 10 ];
  240.     scrn_array[ SCRN7 ] = scrn_pntrs[ 11 ];
  241.     scrn_array[ SCRN8 ] = scrn_pntrs[ 12 ];
  242.  
  243.     /* get the addresses of the work buffers */
  244.     temp_scrn = scrn_pntrs[ 5 ];
  245.     undo_scrn = scrn_pntrs[ 6 ];
  246.  
  247.     /*
  248.     ** set the box flags to enabled/disabled depending
  249.     ** on whether the screen buffer was allocated!
  250.     */
  251.  
  252.     boxflags[0] = boxflags[0] & 0xff00;
  253.     boxflags[1] = boxflags[1] & 0xff00;
  254.  
  255.     for( i = 0; i < 8; i++ )
  256.          {
  257.          if( scrn_array[i] != 0L )
  258.              {
  259.              boxflags[0] = boxflags[0] | (1 << i);
  260.              boxflags[1] = boxflags[1] | (1 << i);
  261.              }
  262.          }
  263.  
  264.     /* get the currently selected screen */
  265.     demsg[0] = 0xDE01;
  266.     demsg[1] = gl_apid;
  267.     demsg[2] = 0;
  268.     appl_write( degas_id, 16, demsg );
  269.  
  270.     do{ evnt_mesag( demsg ); } while( demsg[0] != 0xDE81 );
  271.  
  272.     /* adjust the screen number returned to ignore the work buffers */
  273.     if( demsg[3] < 3 )
  274.         cur_screen = demsg[3] - 1;
  275.     else
  276.         cur_screen = demsg[3] - 5;
  277.  
  278.     /* put an asterisk in front of the screen string if not empty */
  279.     for( i = 0; i < 8; i++ )
  280.          {
  281.          if( scrn_array[i] != 0L )
  282.              {
  283.              if( search_blank( scrn_array[i] ) )
  284.                  boxes[i].string[0] = '*';
  285.              else
  286.                  boxes[i].string[0] = ' ';
  287.              }
  288.          }
  289.  
  290.     /* open the accessory */
  291.     cutflag = 0;
  292.     open_vwork();
  293.     open_window();
  294.  
  295. }   /* End of - acc_open() */
  296.  
  297.  
  298. /**************************************
  299. * acc_close():                        *
  300. * This routine closes the workstation *
  301. **************************************/
  302.  
  303. acc_close( msgbuff )
  304. int msgbuff[];
  305. {
  306.     if( msgbuff[3] == menu_id && wi_handle != -1 )
  307.         {
  308.         v_clsvwk( handle );
  309.         wi_handle = -1;
  310.         }
  311. }
  312.  
  313.  
  314. /***********************************************************************
  315. * move_window():                                                       *
  316. * This routine moves the window to the position specified in msgbuff[] *
  317. ***********************************************************************/
  318.  
  319. move_window( msgbuff )
  320. int msgbuff[];
  321. {
  322.     /* return if move message is not for my window */
  323.     if( msgbuff[3] != wi_handle ) return(0);
  324.  
  325.     /* update the accessory position variables */
  326.     ax = msgbuff[4];
  327.     ay = msgbuff[5];
  328.     aw = msgbuff[6];
  329.     ah = msgbuff[7];
  330.  
  331.     /* set the window position */
  332.     wind_set( msgbuff[3], WF_CURRXYWH, ax, ay, aw, ah );
  333.  
  334.     /* call routine to store work area position in global variables */
  335.     get_workarea();
  336. }
  337.  
  338.  
  339. /************************************************************
  340. * close_window():                                           *
  341. * This routine closes the window and closes the workstation *
  342. ************************************************************/
  343.  
  344. close_window( msgbuff )
  345. int msgbuff[];
  346. {
  347.     /* return if the close message is not for this window */
  348.     if( msgbuff[3] != wi_handle ) return(0);
  349.  
  350.     /* otherwise, close it! */
  351.     wind_close( wi_handle );
  352.     wind_delete( wi_handle );
  353.     v_clsvwk( handle );
  354.     wi_handle = -1;
  355. }
  356.  
  357.  
  358. /****************************************************
  359. * top_window():                                     *
  360. * This routine sets the accessory window to the top *
  361. ****************************************************/
  362.  
  363. top_window( msgbuff )
  364. int msgbuff[];
  365. {
  366.     /* return if the top command is not for my window */
  367.     if( msgbuff[3] != wi_handle ) return(0);
  368.  
  369.     wind_set( wi_handle, WF_TOP, 0, 0, 0, 0 );
  370. }
  371.  
  372.  
  373. /*********************************************************
  374. * show_authors():                                        *
  375. * This routine resorts to some shameless self-promotion! *
  376. *********************************************************/
  377.  
  378. show_authors( msgbuff )
  379. int msgbuff[];
  380. {
  381. static char authors[] = "[1][The Degas Elite Image Generator|\
  382.          Written by|\
  383.     Robert M. Birmingham|\
  384.             and|\
  385.     Richard C. Leinecker][  Ok!  ]";
  386.  
  387.     /* return if the top command is not for my window */
  388.     if( msgbuff[3] != wi_handle ) return(0);
  389.  
  390.     form_alert( 1, authors );
  391. }
  392.  
  393.  
  394. /*************************************************
  395. * redraw():                                      *
  396. * This routine redraws sections of the window by *
  397. * stepping through the window rectangle list.    *
  398. *************************************************/
  399.  
  400. redraw( msgbuff )
  401. int msgbuff[];
  402. {
  403.     int w[4];    /* holds rectangle coord's from window list */
  404.  
  405.  
  406.     /* return if the redraw message isn't for this window */
  407.     if( msgbuff[3] != wi_handle ) return(0);
  408.  
  409.     wind_update(1);
  410.  
  411.     /* get the first rectangle from the window list */
  412.     wind_get( msgbuff[3], WF_FIRSTXYWH, &w[0], &w[1], &w[2], &w[3] );
  413.  
  414.     while( w[2] && w[3] )
  415.            {
  416.            if( b_intersect( &msgbuff[4], w ) )  draw_window( w );
  417.            wind_get( msgbuff[3], WF_NEXTXYWH, &w[0], &w[1], &w[2], &w[3] );
  418.            }
  419.  
  420.     wind_update(0);
  421.  
  422. }   /* End of - redraw() */
  423.  
  424.  
  425. /******************************************************
  426. * get_workarea():                                     *
  427. * This routine gets the window's work area dimensions *
  428. ******************************************************/
  429.  
  430. get_workarea()
  431. {
  432.     wind_get( wi_handle, WF_WORKXYWH, &xwork, &ywork, &wwork, &hwork );
  433. }
  434.  
  435.  
  436. /**********************************************
  437. * check_box():                                *
  438. * This routine processes the box index passed *
  439. **********************************************/
  440.  
  441. check_box( mx, my )
  442. int mx, my;
  443. {
  444.     int i;          /* miscellaneous         */
  445.     int box_index;  /* index of box selected */
  446.     int button;     /* mouse button state    */
  447.  
  448.  
  449.     /* see if the mouse was clicked on an accessory box */
  450.     if( ( box_index = scan_boxes( mx, my ) ) < 0 ) return(0);
  451.  
  452.     /* do nothing if the box is the screen selected */
  453.     if( box_index == cur_screen ) return(0);
  454.  
  455.     /* if the box is disabled then return */
  456.     if(((boxflags[cutflag] >> (box_index-SCRN1)) & 0x0001) == 0) return(0);
  457.  
  458.     /* lock out AES messages */
  459.     wind_update(1);
  460.  
  461.     /*
  462.     ** set the clipping rectangle so the boxes
  463.     ** won't be drawn off the edge of the screen
  464.     */
  465.  
  466.     set_clip( 0, 0, work_out[0], work_out[1], 1 );
  467.  
  468.     /* highlight the box selected */
  469.     draw_box( box_index, 1 );
  470.  
  471.     /* find out which box was pressed */
  472.     if( box_index >= SCRN1 && box_index <= SCRN8 )
  473.         {
  474.         draw_box( cur_screen, 0 );
  475.         cur_screen = box_index;
  476.         }
  477.     else if( box_index == CUTIMAGE )
  478.         {
  479.         cutflag = cut_image( scrn_array[cur_screen], cutflag );
  480.  
  481.         for( i = TO_C; i <= TO_DATA; i++ )
  482.              {
  483.              if( i == cur_screen )
  484.                  draw_box( i, 1 );
  485.              else
  486.                  draw_box( i, 0 );
  487.              }
  488.         }
  489.     else
  490.         image( scrn_array[ cur_screen ], box_index );
  491.  
  492.     /* wait for the mouse button to be released */
  493.     do{ graf_mkstate( &i, &i, &button, &i ); } while( button );
  494.  
  495.     /* reset the box unless it's a 'screen' box */
  496.     if( box_index != cur_screen ) draw_box( box_index, 0 );
  497.  
  498.     /* clear the clipping rectangle */
  499.     set_clip( 0, 0, work_out[0], work_out[1], 0 );
  500.  
  501.     /* enable AES messages */
  502.     wind_update(0);
  503.  
  504. }   /* End of - check_box() */
  505.  
  506.  
  507. /**********************************************************
  508. * scan_boxes():                                           *
  509. * Returns the box under the mouse position passed, if any *
  510. **********************************************************/
  511.  
  512. scan_boxes( x, y )
  513. int x, y;
  514. {
  515.     int i;
  516.  
  517.     /* see if the mouse cursor is inside a box */
  518.     for( i = SCRN1; i <= TO_DATA; i++ )
  519.          {
  520.          if( x >= xwork + boxes[i].x &&
  521.              y >= ywork + boxes[i].y &&
  522.              x <= xwork + boxes[i].x + boxes[i].w &&
  523.              y <= ywork + boxes[i].y + boxes[i].h )
  524.              return(i);
  525.          }
  526.  
  527.     return(-1);
  528.  
  529. }   /* End of - scan_boxes() */
  530.  
  531.  
  532. /*******************************************
  533. * draw_window():                           *
  534. * This routine redraws the accesory window *
  535. *******************************************/
  536.  
  537. draw_window( w )
  538. int w[];
  539. {
  540.     int i;            /* general purpose variable  */
  541.     int pxyarray[4];  /* used to clear the window  */
  542.     int clip[4];      /* clipping rectangle to set */
  543.  
  544.  
  545.     /* set the clipping rectangle */
  546.     clip[0] = w[0];
  547.     clip[1] = w[1];
  548.     clip[2] = w[0] + w[2] - 1;
  549.     clip[3] = w[1] + w[3] - 1;
  550.     vs_clip( handle, 1, clip );
  551.  
  552.     /* clear the work area */
  553.     pxyarray[0] = xwork;
  554.     pxyarray[1] = ywork;
  555.     pxyarray[2] = xwork + wwork - 1;
  556.     pxyarray[3] = ywork + hwork - 1;
  557.  
  558.     /* set the various attributes for the box */
  559.     v_hide_c( handle );
  560.     vsf_color( handle, 0 );
  561.     vsf_interior( handle, 2 );
  562.     vsf_style( handle, 8 );
  563.     vr_recfl( handle, pxyarray );
  564.  
  565.     /* redraw each box (highlight the active screen box) */
  566.     for( i = SCRN1; i <= TO_DATA; i++ )
  567.          {
  568.          if( i == cur_screen )
  569.              draw_box( i, 1 );
  570.          else
  571.              draw_box( i, 0 );
  572.          }
  573.  
  574.     /* reset the clipping rectangle */
  575.     vs_clip( handle, 0, clip );
  576.     v_show_c( handle, 0 );
  577.  
  578. }   /* End of - draw_window() */
  579.  
  580.  
  581. /******************************************************************
  582. * draw_box():                                                     *
  583. * This routine redraws the box whose array index number is passed *
  584. ******************************************************************/
  585.  
  586. draw_box( idx, flag )
  587. int idx, flag;
  588. {
  589.     int pxyarray[4];   /* rectangle for drawing box  */
  590.     int shadow[4];     /* rectangle for box's shadow */
  591.     int x, y;          /* position of box's text     */
  592.  
  593.  
  594.     /* use the box flags to see if the box should be enabled/disabled */
  595.     if( ((boxflags[cutflag] >> (idx-SCRN1)) & 0x0001) == 0 )
  596.         vst_effects( handle, 2 );
  597.     else
  598.         vst_effects( handle, 0 );
  599.  
  600.     /* get the box's coordinates */
  601.     pxyarray[0] = xwork + boxes[ idx ].x;
  602.     pxyarray[1] = ywork + boxes[ idx ].y;
  603.     pxyarray[2] = pxyarray[0] + boxes[ idx ].w;
  604.     pxyarray[3] = pxyarray[1] + boxes[ idx ].h;
  605.  
  606.     /* set the shadow box coodinates */
  607.     shadow[0] = pxyarray[0] + 2;
  608.     shadow[1] = pxyarray[1] + 2;
  609.     shadow[2] = pxyarray[2] + 2;
  610.     shadow[3] = pxyarray[3] + 2;
  611.  
  612.     /* draw the shadow of the box */
  613.     v_hide_c( handle );
  614.     vswr_mode( handle, 1 );
  615.     vsf_perimeter( handle, 1 );
  616.     vsf_color( handle, 1 );
  617.     vsf_interior( handle, 1 );
  618.     v_bar( handle, shadow );
  619.  
  620.     /* draw it as an outline, or as selected based on the flag */
  621.     vsf_interior( handle, flag );
  622.     v_bar( handle, pxyarray );
  623.  
  624.     /* print the string in the box */
  625.     x = (boxes[idx].w / 2) - ((strlen(boxes[idx].string) * gr_hwchar)/2);
  626.     x = pxyarray[0] + x;
  627.     y = pxyarray[3] - 3;
  628.  
  629.     vswr_mode( handle, 3 );
  630.     v_gtext( handle, x, y, boxes[idx].string );
  631.     vswr_mode( handle, 1 );
  632.     vst_effects( handle, 0 );
  633.     v_show_c( handle, 1 );
  634.  
  635. }  /* End of - draw_box() */
  636.  
  637.  
  638. /************************************************************
  639. * initialize():                                             *
  640. * This routine initializes the box array and opens a window *
  641. ************************************************************/
  642.  
  643. initialize()
  644. {
  645.     int i, a;   /* miscellaneous variables */
  646.  
  647.  
  648.     /* tell GEM we're here, and install our DESK item... */
  649.     appl_init();
  650.     handle = graf_handle( &gr_hwchar, &gr_hhchar, &i, &i );
  651.     menu_id = menu_register( gl_apid, "  The Generator..." );
  652.  
  653.     rez = Getrez();      /* get the current screen resolution */
  654.     cur_screen = SCRN1;  /* set the initial screen selected   */
  655.     wi_handle = -1;      /* indicate no window is open!       */
  656.  
  657.     /* initialize the box position array... */
  658.     for( a = SCRN1; a <= TO_DATA; a++ )
  659.          {
  660.          boxes[ a ].x = boxes[ a ].x * gr_hwchar;
  661.          boxes[ a ].y = (gr_hhchar/2 ) + (boxes[ a ].y * gr_hhchar);
  662.          boxes[ a ].w = boxes[ a ].w * gr_hwchar;
  663.          boxes[ a ].h = boxes[ a ].h * gr_hhchar + 3;
  664.          }
  665.  
  666.     /* calculate the initial window position and dimension */
  667.     ax = 5 * gr_hwchar;
  668.     ay = 2 * gr_hhchar;
  669.     aw = boxes[TO_DATA].x+boxes[TO_DATA].w+gr_hwchar+2;
  670.     ah = boxes[TO_DATA].y+boxes[TO_DATA].h+gr_hhchar+(gr_hhchar/2)+6;
  671.  
  672. }   /* End of - initialize() */
  673.  
  674.  
  675. /*******************************************************
  676. * open_vwork():                                        *
  677. * This routine opens the workstation for the accessory *
  678. *******************************************************/
  679.  
  680. open_vwork()
  681. {
  682.     int i;
  683.  
  684.     for( i = 0; i < 10; work_in[ i++ ] = 1 );
  685.     work_in[ 10 ] = 2;
  686.     v_opnvwk( work_in, &handle, work_out );
  687. }
  688.  
  689.  
  690. /*******************************************************
  691. * open_window():                                       *
  692. * This routine opens the window used for the accessory *
  693. *******************************************************/
  694.  
  695. open_window()
  696. {
  697.     /* create, then open the accessory window */
  698.     wi_handle = wind_create( WI_KIND, 0, 0, aw, ah );
  699.     wind_set( wi_handle, WF_NAME, "DE Image Generator", 0, 0 );
  700.     wind_open( wi_handle, ax, ay, aw, ah );
  701.     get_workarea();
  702. }
  703.  
  704.  
  705. /**********************************************************
  706. * set_clip():                                             *
  707. * This routine enables or disables the clipping rectangle *
  708. **********************************************************/
  709.  
  710. set_clip( x, y, w, h, flag )
  711. int x, y, w, h, flag;
  712. {
  713.     int clip[4];
  714.  
  715.     clip[0] = x;
  716.     clip[1] = y;
  717.     clip[2] = x + w;
  718.     clip[3] = y + h;
  719.  
  720.     vs_clip( handle, flag, clip );
  721. }
  722.  
  723.  
  724. /*********************************************************
  725. * rectangle intersection routines for the window redraws *
  726. *********************************************************/
  727.  
  728. int b_intersect( bin, bout )
  729. int bin[], bout[];
  730. {
  731. return r_intersect(bin[0],bin[1],bin[2],bin[3],
  732.                    &bout[0],&bout[1],&bout[2],&bout[3] );
  733. }
  734.  
  735.  
  736. r_intersect( bx, by, bw, bh, ox, oy, ow, oh )
  737. int bx, by, bw, bh, *ox, *oy, *ow, *oh;
  738. {
  739.     int x, y, w, h;
  740.  
  741.  
  742.     w = minimum( bx + bw, *ox + *ow );
  743.     h = minimum( by + bh, *oy + *oh );
  744.     x = maximum( *ox, bx );
  745.     y = maximum( *oy, by );
  746.  
  747.     *ox = x;
  748.     *oy = y;
  749.     *ow = w - x;
  750.     *oh = h - y;
  751.  
  752.     return w > x && h > y;
  753. }
  754.  
  755.